<?php
/**
 * Created by PhpStorm.
 * User: zd
 * Date: 2018/12/5
 * Time: 15:58
 */

namespace app\enterprise\service;


class Message
{
    public $url = '';
    function __construct()
    {
        $this->url = config('setting.base_url');
    }
    /**
     * 获取workeruser的信息
     * @param $token
     * @return null
     */
    public function getWorkerUserInfo($token){
        $url=$this->url."/enterprise/user";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 获取用户信息
     * @param $token
     * @param $uid
     * @return null
     */
    public function getUserInfo($token,$uid){
        $url=$this->url."/user/info/".$uid;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }


    /**
     * 获取用户列表
     * @param $token
     * @return null
     */
    public function getMessage($token){
        $url=$this->url."/message/user";
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }
    /**
     * 获取信息列表
     * @param $token
     * @return null
     */
    public function getMessageList($uid,$page,$token){
        $url=$this->url."/message/list";
        $params = ['uid'=>$uid,'page'=>$page];
        $result = curl_post($url,$token,$params);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 改变消息状态
     * @param $uid
     * @param $token
     * @return null
     */
    public function changeMessageStatus($uid,$token){
        $url=$this->url."/message/user/status/".$uid;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

    /**
     * 删除联系人
     * @param $uid
     * @param $token
     * @return null
     */
    public function deleteUser($uid,$token){
        $url=$this->url."/message/user/delete/".$uid;
        $result = curl_get($url,$token);
        $data = json_decode($result);
        if ($data->code = 200){
            return $data->content;
        }else{
            return null;
        }
    }

}